package com.youyou.fusheng2.View.Adapter;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.youyou.fusheng2.R;

import java.util.List;
import java.util.Map;

/**
 * @name fusheng2
 * @class name：com.youyou.fusheng2.View.Adapter
 * @anthor 浮生 QQ:2567294605
 * @time 2020/8/20 17:22
 * @to
 */
public class HomeListsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{

    private List<Map<String, String>> listTests;

    public void setListTests(List<Map<String, String>> listTests) {
        this.listTests = listTests;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.home_imageitem, parent,false);
        return new HomeList(inflate);
    }

    @SuppressLint("ResourceAsColor")
    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof HomeList) {
            ((HomeList) holder).imageView.setBackgroundColor(R.color.homeList);
            Glide.with(holder.itemView.getContext()).load(listTests.get(position).get("pic")).into(((HomeList) holder).imageView);
            ((HomeList) holder).home_text.setText(listTests.get(position).get("tname"));
            ((HomeList) holder).imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Bundle bundle = new Bundle();
                    bundle.putInt("f", Integer.parseInt(listTests.get(position).get("tid")));
                    holder.itemView.getContext().startActivity(new Intent(holder.itemView.getContext(), com.youyou.fusheng2.View.Activity.playVdioActivity.class).putExtra("text", bundle));
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return 10;
    }

    private class HomeList extends RecyclerView.ViewHolder {

        ImageView imageView;
        TextView  home_text;

        public HomeList(View inflate) {
            super(inflate);
            imageView = inflate.findViewById(R.id.home_image);
            home_text = inflate.findViewById(R.id.home_text);
        }
    }
}
